using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Pronghorn.Core
{
	public class ProngHornApplication : HttpApplication
	{
		public static IIocContainer GetContainer()
		{
			var container = new CastleWindsorContainer();
			return GetContainer(container);
		}

		public static IIocContainer GetContainer(IIocContainer container)
		{
			container.AddComponent<MinimizeAndCombineJsController>("Pronghorn.Core.MinimizeAndCombineJsController");
			container.AddComponent<MinimizeAndCombineCssController>("Pronghorn.Core.MinimizeAndCombineCssController");
			container.AddComponent("fileMinifier", typeof (IFileMinifier), typeof (SimpleFileMinifier));
			container.AddComponent("lib", typeof(IFileConventions), typeof(LibFileConventions));
			container.AddComponent("skin", typeof(IFileConventions), typeof(SkinFileConventions));
			container.AddComponent("widget", typeof(IFileConventions), typeof(WidgetFileConventions));
			container.AddComponent("theme", typeof(IFileConventions), typeof(ThemeFileConventions));
			container.AddComponent("jsFileLocator", typeof(IFileLocator), typeof(ConventionJsFileLocator));
			container.AddComponent("cssFileLocator", typeof(IFileLocator), typeof(ConventionCssFileLocator));
			container.AddComponent("SiteService", typeof(ISiteService), typeof(SiteService));
			container.AddComponent("SkinContext", typeof(IProngHornSkinContext), typeof(ProngHornSkinContext));
			return container;
		}

		public static void RouteRegistration(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
			routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
			routes.MapRoute(
				"Scripts", // Route name
				"scripts/js/{files}", // URL with parameters
				new { controller = "MinimizeAndCombineJs", action = "Index", files = "" } // Parameter defaults
				);
		}
	}
}